package com.wxyzz.satserver.article.controller;

import com.wxyzz.common.core.common.PageParam;
import com.wxyzz.common.core.common.R;
import com.wxyzz.common.core.entity.Article;
import com.wxyzz.satserver.article.param.ArticleAddParam;
import com.wxyzz.satserver.article.param.CommentAddParam;
import com.wxyzz.satserver.article.service.ArticleService;
import com.wxyzz.satserver.article.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;



@RestController
@RequestMapping("/article")
@Api(tags ="文章api")
@CrossOrigin
public class ArticleController {

    @Resource
    private ArticleService articleService;

//展示发布文章首页分页展示的信息   ok填写
    @GetMapping ("/pageInfo")
    @ApiOperation(value = "分页查询文章")
    public R  pageInfo(PageParam param){
        PageVO<ArticleVO> articleVOPageVO = articleService.pageInfo(param);
        return  R.ok(articleVOPageVO);
    }

//首页，点击封面查看本篇文章的详细信息 ok填写
    @GetMapping("/articleInfo")
    @ApiOperation(value = "文章的详细")
    public R  articleInfo(Integer aid){
        ShowArticleVO articleById = articleService.findArticleById(aid);
        return R.ok(articleById);
    }

//模糊查询相关热门文章根据label ok填写
    @GetMapping("/popularArticle")
    @ApiOperation(value = "查询文章")
    public R  popularArticle(String label){
        List<Article> popularArticle = articleService.findPopularArticle(label);
        return R.ok(popularArticle);
    }

//发布文章将发布的文章信息存入到数据库 ok填写
    @PostMapping("/addArticle")
    @ApiOperation(value = "发布的文章")
    public R  addArticle(@RequestBody ArticleAddParam param){
        articleService.saveArticle(param);
        return R.ok();
    }

//发布文章的时候上传图片文件到minio ok填写
    @PostMapping("/uploadFile")
    @ApiOperation(value = "上传图片")
    public R  uploadFile(@RequestBody  MultipartFile file){
        String img = articleService.uploadFile(file);
        return  R.ok(img);
    }

//展示在文章下面发布评论的用户信息，根据文章id查询 ok填写
    @GetMapping ("/showComment")
    @ApiOperation(value = "查询文章评论")
    public R comment(Integer aid){
        List<CommentVO> commentInfo = articleService.findCommentInfo(aid);
        return  R.ok(commentInfo);
    }

//进行评论添加相关用户的评论信息  ok填写
    @PostMapping("/addComment")
    @ApiOperation(value = "发布评论")
    public R addComment(@RequestBody CommentAddParam param){
        articleService.addCommentInfo(param);
        return  R.ok();
    }

    // 查询热门标签
    @ApiOperation(value = "查询热门标签")
    @GetMapping("/hostLable")
    public R getHostLable() {
        String hostTopic = articleService.getHostTopic();
        return R.ok(hostTopic);
    }

//查找热门话题文章
    @GetMapping("/hostTopicArticle")
    @ApiOperation(value = "根据标签查询文章")
    public R getHostTopicArticle(String hostLable) {
        List<HostLableArticle> hostLableArticle = articleService.getHostLableArticle(hostLable);
        return R.ok(hostLableArticle);
    }

    // 查找热门话题文章详情
    @GetMapping("/topicArticleDetails")
    @ApiOperation(value = "根据文章id查询文章详情")
    public R getTopicArticleDetails(Integer aid) {
        ArticleDetail articleDetail = articleService.ArticleDetail(aid);
        return R.ok(articleDetail);
    }

    //前端我的页面，所登录用户自己发布的文章动态
    @GetMapping ("/myPageInfo")
    @ApiOperation(value = "我的--这个板块中，登录用户自己发布的动态信息")
     public R  MyPageInfo(PageParam param){
         MyPageVO<ArticleVO> articleVOPageVO = articleService.myPageInfo(param);
         return  R.ok(articleVOPageVO);
     }


}
